"""
    通过调用deepseek实现用户意图识别，同时提取intent和slot
"""

from dotenv import load_dotenv

load_dotenv()

import os
from openai import OpenAI

with open('prompt.txt', 'r', encoding='utf-8') as prompt:
    SYSTEM_PROMPT = prompt.read()


def llm_predict(prompt):
    """
    接收用户录入的提示词, 调用DeepSeek模型获取结果, 并返回.
    :param prompt: 提示词
    :return: 模型响应结果
    """

    # 1. 创建API客户端实例.
    # 参2: base_url, 指定API请求的基础地址.
    client = OpenAI(
        api_key=os.getenv('API_KEY'),
        base_url=os.getenv('BASE_URL')
    )

    response = client.chat.completions.create(
        model="deepseek-chat",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": prompt},
        ],
        stream=False
    )

    return response.choices[0].message.content


if __name__ == '__main__':
    # 1. 测试1: 获取分类
    res1 = llm_predict('预订今天晚上从无锡到昆明的长途客车')
    print(res1)
